<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<div id="hq_update_div">
<script src="${pageContext.request.contextPath}/erp/js/showImg.js" type="text/javascript"></script>
<style type="text/css">
	img{
		width: 150px;
		height: 150px;
		cursor: pointer;
	}
</style>
	<form method="post" action="${pageContext.request.contextPath}/hq/update" id="update_hq_from"
		class="pageForm required-validate" enctype="multipart/form-data" onsubmit="return iframeCallback(this,navTabAjaxDone);">	
		<div layouth="56" class="pageFormContent" style="height: 186px; overflow: auto;">
			<p>
				<label>总部编码：</label>
				<input type="text" readonly="readonly" size="15" class="textInput" id="hqId" name="hqId" value="${bean.hqId }"/>
			</p>
			<p>
				<label>总部名称：</label>
				<input type="text" size="15" readonly="readonly" class="textInput" name="hqName" id="hqName" value="${bean.hqName }"/>
			</p>
			<p>
				<label>营业执照名称：</label>
				<input type="text" size="15" class="required textInput" name="registeredName" id="registeredName" value="${bean.registeredName }"/>
			</p>
			<p>
				<label>营业执照编号：</label>
				<input type="text" size="15" class="required textInput" name="registeredNumber" id="registeredNumber" value="${bean.registeredNumber }"/>
			</p>
			<p>
				<label>法人/代理人：</label>
				<input type="text" size="15" class="required textInput" name="legalRepresentative" id="legalRepresentative" value="${bean.legalRepresentative }"/>
			</p>
			<p>
				<label>联系人：</label>
				<input type="text" size="15" class="required textInput" name="contactsName" id="contactsName" value="${bean.contactsName }"/>
			</p>
			<p>
				<label>电话：</label>
				<input type="text" size="15" class="required textInput" name="phoneNum" id="phoneNum" value="${bean.phoneNum }"/>
			</p>
			<p>
				<label>邮箱：</label>
				<input type="text" size="15" class="required textInput" name="email" id="email" value="${bean.email }"/>
			</p>
			<p>
				<label>备注：</label>
				<input type="text" size="15" class="textInput" name="memo" id="memo" value="${bean.memo }"/>
			</p>
			<p style="width: 500px;">
				<label>地址：</label>
		           <select data-placeholder="省份" id="provinceId" name="provinceId" class="select" >
		           	<option value="">选择省份</option>
		           </select>
		           <input type="hidden" id="old_provinceId" value="${bean.provinceId}"/>
		           <input type="hidden" size="15" class="textInput" name="province" id="province" value="${bean.province}">
		           <select data-placeholder="城市" name="cityId" id="cityId" class="form-control" data-rel="chosen">
		           		<option value="">选择城市</option>
		          	</select>
		           <input type="hidden" id="old_cityId" value="${bean.cityId}"/>
		          	<input type="hidden" size="15" class="textInput" name="city" id="city" value="${bean.city}"/>
<!--  		           <select data-placeholder="区域" name="area" id="areaId" class="form-control" data-rel="chosen"> -->
<!-- 		               <option>选择区域</option> -->
<!--  		           </select> -->
			</p>
			<p style="width: 200px;">
		      <input id="address" name="address" class="required textInput" type="text" value="${bean.address }"/>
			</p>
			<div class="divider"></div>
			<p style="height: 150px;">
				<label>logo：</label>
				<c:choose>
				   <c:when test="${bean.logoUrl == '' }"> 
						<img src="${pageContext.request.contextPath}/images/upload.png" name="hq_file_img" id="hq_file_img" onclick="show_img.open_file('hqFile')"/>
				   </c:when>
				   <c:otherwise>
						<img src="${pageContext.request.contextPath}/Common/downloadPhoto?url=${bean.logoUrl }" name="hq_file_img" id="hq_file_img" onclick="show_img.open_file('hqFile')"/>
				   </c:otherwise>
				</c:choose>	
				<input type="file" id="hqFile" name="hqFile" style="display: none"  onchange="show_img.change('hqFile','hq_file_img')"/>
			</p>
		</div>
		 <div class="formBar">
			<ul>
				<!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
				<li><div class="buttonActive"><div class="buttonContent"><button type="button" onclick="from_submit()">保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
				</li>
			</ul>
		</div>
	</form>
	<script type="text/javascript">
	var from = $("#update_hq_from");
	 $(document).ready(function () {
   			 var old_provinceId = $(from).find("#old_provinceId").val();
	    	$.post("${pageContext.request.contextPath}/address/listProvinces", 
			   function(data){
	    		 if(data.code == 200){
	                    var result = "<option value=''>选择省份</option>";
	                    $.each(data.list,function(n,value){
	                    	if(old_provinceId*1 == value.provinceId*1){
	                    		result +="<option value='"+value.provinceId+"' selected='selected'>"+value.province+"</option>";
	                    	}else{
		                        result +="<option value='"+value.provinceId+"'>"+value.province+"</option>";
	                    	}
	                    });
	                    $(from).find("#provinceId").html('');
	                    $(from).find("#provinceId").append(result);
	                    list_city();
	                }
			   });
	    	$(from).find("#provinceId").change(function(){list_city()});
	    	
	    	$(from).find("#cityId").change(function () {
	        	 $(from).find("#city").val($(from).find("#cityId").find("option:selected").text());
//	        	$.post("${pageContext.request.contextPath}/address/listAreas",{cityId:$("#cityId").val()}, 
//     			   function(data){
//  	    		 if(data.code == 200){
//  	                    var result = "<option>选择区域</option>";
//  	                    $.each(data.list,function(n,value){
//  	                    	console.debug(value.areaId);
//  	                    	result +="<option value='"+value.areaId+"'>"+value.area+"</option>";
//  	                    });
// 				    		 $("#areaId").html('');
//	                   		 $("#areaId").append(result);
//  	                }
//     			   });
	        });
	    });
	 function list_city() {
		 
    	 $(from).find("#province").val( $(from).find("#provinceId").find("option:selected").text());
		var provinceId = $(from).find("#provinceId").val();
       var result = "<option value=''>选择城市</option>";
		if(provinceId == ""){
			 $(from).find("#cityId").html('');
			 $(from).find("#cityId").append(result);             
			return;
		}
    	$.post("${pageContext.request.contextPath}/address/listCity",{provinceId:$(from).find("#provinceId").val()}, 
		   function(data){
	 		 if(data.code == 200){
	 			var old_cityId = $(from).find("#old_cityId").val();
	              $.each(data.list,function(n,value){
	            	  if(old_cityId == value.cityId){
                    	 result +="<option value='"+value.cityId+"' selected='selected'>"+value.city+"</option>";
                 	  }else{
                   	 	result +="<option value='"+value.cityId+"'>"+value.city+"</option>";
	                  }
	              });
	             $(from).find("#cityId").html('');
	            $(from).find("#cityId").append(result);
	          }
		   });
    };
    function from_submit(){  
		var provinceId =  $(from).find("#provinceId").val();
		var cityId =  $(from).find("#cityId").val();
		if(provinceId == ""){
			alertMsg.error("省份不能为空");
			return false;
		}
		if(cityId == ""){
			alertMsg.error("城市不能为空");
			return false;
		}
		$(from).submit(); 
	    
	} 
	</script>
</div>